package com.zhongkun.datahome.web.app;

import com.zhongkun.datahome.common.core.domain.R;
import com.zhongkun.datahome.common.enums.DataSettingLinkTypeEnum;
import com.zhongkun.datahome.service.req.qry.assets.AppDataAssetsQry;
import com.zhongkun.datahome.service.req.qry.assets.DataAssetsQry;
import com.zhongkun.datahome.service.req.qry.file.SignFileQry;
import com.zhongkun.datahome.service.req.qry.material.HouseMaterialQry;
import com.zhongkun.datahome.service.service.ICommonFileService;
import com.zhongkun.datahome.service.service.IDataAssetsService;
import com.zhongkun.datahome.service.service.IHouseMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: lifengsheng
 * @Date: 2025/5/9 14:44
 * @Desc
 */
@Api("小程序接口")
@RestController
@RequestMapping("/app/dataAssets")
public class DataAssetsAppController {
    @Resource
    private IDataAssetsService dataAssetsService;

    @Resource
    private ICommonFileService commonFileService;

    @Resource
    private IHouseMaterialService houseMaterialService;

    @ApiOperation("根据图标获取数据资料")
    @PostMapping("/getByDataSettingIdAndLinkType")
    public R<List<?>> getByDataSettingIdAndLinkType(@RequestBody AppDataAssetsQry qry) {
        if (DataSettingLinkTypeEnum.SIGN_FILE.is(qry.getLinkType())) {
            return R.ok(commonFileService.list(SignFileQry.of(qry.getHouseId())));
        }
        if (DataSettingLinkTypeEnum.MATERIAL_LIST.is(qry.getLinkType())) {
            return R.ok(houseMaterialService.listBy(HouseMaterialQry.of(qry)));
        }

        return R.ok(dataAssetsService.listByHouseId(DataAssetsQry.of(qry.getHouseId(), qry.getDataSettingId(), 1)));
    }
}
